#ifndef __MINIUTIL_UTIL_UUID_H__
#define __MINIUTIL_UTIL_UUID_H__

namespace miniutil 
{
  #define UUIDS_PER_TICK 1024

  /* Set the following to a call to acquire a system wide global lock
  */
  #define LOCK
  #define UNLOCK

  typedef unsigned int   unsigned32;
  typedef unsigned short  unsigned16;
  typedef unsigned char   unsigned8;
  typedef unsigned char   byte;
  /* Set this to what your compiler uses for 64 bit data type */
  #ifdef WIN32
  #define unsigned64_t unsigned __int64
  #define I64(C) C
  #else
  #define unsigned64_t unsigned long long
  #define I64(C) C##LL
  #endif


  typedef unsigned64_t uuid_time_t;
  typedef struct {
    char nodeID[6];
  } uuid_node_t;

	struct util_uuid_t {
	  unsigned32          time_low;
	  unsigned16          time_mid;
	  unsigned16          time_hi_and_version;
	  unsigned8           clock_seq_hi_and_reserved;
	  unsigned8           clock_seq_low;
	  byte                node[6];
	};
	
	class miniuuid
	{
		public:
			miniuuid();
			miniuuid(unsigned8 hash[16]);
			miniuuid(util_uuid_t nsid, void* name, int namelen);
			miniuuid(unsigned16 clock_seq, uuid_time_t timestamp, uuid_node_t node);

			int get_uuid(util_uuid_t &);
			int get_uuid(char*, int len); // len must equal 16
			int compare(const miniuuid&);
		private:
			util_uuid_t muuid;
			void initial(unsigned16 clock_seq, uuid_time_t timestamp, uuid_node_t node);
			void initial(unsigned8 hash[16]);
		public:
			static int getuuid(util_uuid_t &);
			static int getuuid(char*, int len);

	};
}

#endif
